package com.jorado.core.utility;

import java.util.Calendar;

public enum TimeUnit {
    SECOND(13, 1),
    MINUTE(12, 1),
    HOUR(10, 1),
    DAY(5, 1),
    ;

    private int interval;

    public int getInterval() {
        return interval;
    }

    public TimeUnit adjustInterval(int interval) {

        this.interval = interval;
        if (this == TimeUnit.SECOND) {
            TimeUnit unit = TimeUnit.SECOND;
            unit.interval = interval;
            return unit;
        } else if (this == TimeUnit.HOUR) {
            TimeUnit unit = TimeUnit.HOUR;
            unit.interval = interval;
            return unit;
        } else if (this == TimeUnit.DAY) {
            TimeUnit unit = TimeUnit.DAY;
            unit.interval = interval;
            return unit;
        } else {
            TimeUnit unit = TimeUnit.MINUTE;
            unit.interval = interval;
            return unit;
        }

    }

    private int value;

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    TimeUnit(int value, int interval) {
        this.value = value;
        this.interval = interval;
    }

    public Calendar addNextTime() {
        Calendar nextTime = Calendar.getInstance();
        nextTime.add(this.getValue(), this.getInterval());
        return nextTime;
    }

}
